package com.qzimp.fujiancuo.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.qzimp.fujiancuo.entity.Userinfo;
import com.qzimp.fujiancuo.entity.UserinfoLog;
import com.qzimp.fujiancuo.entity.vo.UserinfoHaveLogsVo;
import com.qzimp.fujiancuo.entity.vo.UserinfoLogsHaveLogsVo;
import com.qzimp.fujiancuo.mapper.UserinfoLogMapper;
import com.qzimp.fujiancuo.mapper.UserinfoMapper;
import com.qzimp.fujiancuo.service.UserinfoLogService;
import com.qzimp.fujiancuo.service.UserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  服务层实现。
 *
 * @author 吴宗波
 * @since 2024-11-21
 */
@Service
public class UserinfoLogServiceImpl extends ServiceImpl<UserinfoLogMapper, UserinfoLog> implements UserinfoLogService {

    @Autowired
    private UserinfoLogMapper userinfoLogMapper;
    @Autowired
    private UserinfoMapper userinfoMapper;

    @Autowired
    private UserinfoService userinfoService;

    public List<UserinfoLog> findUserinfoLogsById(Integer admin_id) {
       //select * from  userinfo_log wherer admin_id=?
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("userinfo_id",admin_id);

        return userinfoLogMapper.selectListByQuery(queryWrapper);
    }
//    根据日志查询该日志的操作者的信息 用户账户 以及 日志信息（loginName,userinfoLog）
    public UserinfoLogsHaveLogsVo findUserinfoHaveLogsVo2(String log) {

        //根据日志名查询日志信息
        UserinfoLog userinfoLog=userinfoLogMapper.selectBylog(log);
        Integer userinfoId = userinfoLog.getUserinfoId();//日志对应的用户id
        //根据用户id查询用户
        Userinfo userinfo=userinfoMapper.selectByuserinfoId(userinfoId);
        String loginName = userinfo.getLoginName();//用户名
        UserinfoHaveLogsVo userinfoHaveLogsVo = userinfoService.findUserinfoHaveLogsVo(loginName);
        UserinfoLogsHaveLogsVo userinfoLogsHaveLogsVo=new UserinfoLogsHaveLogsVo();
        userinfoLogsHaveLogsVo.setLog(log);
        userinfoLogsHaveLogsVo.setUserinfo(userinfo);
       userinfoLogsHaveLogsVo.setUserinfoLog(userinfoHaveLogsVo);

        return userinfoLogsHaveLogsVo;
    }
}
